#ifndef INC_NODE
#define INC_NODE

class Node
{	// used to create a list with valid positions
    private:
        int _row;
        int _col;
		Node* _nextNode;

    public:
        Node(int row, int col)
        {
            _row = row;
			_col = col;
			_nextNode = NULL;
        }
		
		~Node()
		{
			_nextNode = NULL;
		}

        int getRow()
        {
            return this->_row;
        }

		int getCol()
        {
            return this->_col;
        }

		void setNextNode(Node* nextNode)
        {
            _nextNode = nextNode;
        }
		
		Node* getNextNode()
        {
			return this->_nextNode;
        }
};


class NodeList
{
    private:
        Node*	_firstNode;
		Node*	_lastNode;
        int		_size;

    public:
        NodeList()
        {
            _firstNode	= NULL;
			_lastNode	= NULL;
            _size = 0;
        }
		
		NodeList(NodeList* list)
        {
			_firstNode	= list->getFirstNode();
			_lastNode	= list->getLastNode();
			_size = list->getSize();
        }

		~NodeList() 
		{						
			for (;this->_size>0 ;) 
			{
				Node* index  = _firstNode;
				if (index->getNextNode() != NULL)
				{				
					Node* index1  = index->getNextNode();
					while(index1 -> getNextNode() != NULL){
						index  = index->getNextNode();
						index1 = index->getNextNode();}
					delete index1;
					index->setNextNode(NULL);
					this->_size--;
				}
				else
				{
					delete index;
					this->_size--;
				}
			}
		}

        void addNode(Node* newNode)
        {	//add a new node at a random position
			if (_firstNode == NULL) {
				this->_firstNode	= newNode;
				this->_lastNode		= newNode;
				this->_size			= 1;
			}
			else {
				/*int pos = rand()%_size+1;
				if (pos == 1)
				{
					newNode->setNextNode(_firstNode);
					this->_firstNode	= newNode;
					this->_size++;
				}
				if (pos == _size+1)
				{
					this->_lastNode->setNextNode(newNode);
					this->_lastNode		= newNode;
					this->_size++;
				}
				if (pos>1 && pos<_size+1)
				{
					Node* index	= _firstNode;	
					for(int i=2 ; i<pos ; i++)
					{
						index = index->getNextNode();
					}
					newNode->setNextNode(index->getNextNode());
					index->setNextNode(newNode);
					this->_size++;
				}*/
				Node* index  = _firstNode;
				while(index -> getNextNode() != NULL)
				{
					index = index->getNextNode();
				}
				index->setNextNode(newNode);
				this->_size++;
			}			
        }

		Node* getFirstNode()
        {
            return this->_firstNode;
        }
		
		Node* getLastNode()
        {
            return this->_lastNode;
        }

		int getSize()
        {
            return this->_size;
        }
};

#endif